package jk.zmn.socket.tcp.demo1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 张梦楠
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/5/3116:53
 * @blog www.itzmn.com
 *
 *
 * 服务端
 * 1、构建客户端，发送接收数据
 *
 */
public class ServerDemo1 {

     public static void main(String[] args) throws Exception{

         ServerSocket serverSocket = new ServerSocket(8888);


         //接收客户端连接，阻塞式
         Socket socket = serverSocket.accept();
         System.out.println("有客户端链接上了" );
         DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
         dataOutputStream.writeUTF("欢迎你");
         dataOutputStream.flush();

         DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
         String s = dataInputStream.readUTF();
         System.out.println(s);




     }

     //发送数据



}
